// components/tabbar/tabbar.js
import utils from '../utils/util'
const url = utils.getCurrentPageUrl
Component({
  /**
   * 组件的属性列表
   */
  // properties: {
  //   imageStatus: {
  //     type: String,
  //     value: ''
  //   },
  //   mineImage: {
  //     type: String,
  //     value: ''
  //   }
  // },

  /**
   * 组件的初始数据
   */
  data: {
    isRotate: true,
    isUp: false, // 是否向上，是则可以操作回到上方
    homeimg: 'click',
    imageStatus: '/images/icon/home/home.png', // 方向向上则home-up，否则home-click
    mineImage: '/images/icon/home/mine.png',
    imageHome1: '/images/icon/home/home.png',
    imageHome2: '/images/icon/home/home-click.png',
    imageHome3: '/images/icon/home/home-up.png',
    imageAdd: '/images/icon/home/add.png',
    imageMine: '/images/icon/home/mine.png',
    imageMine1: '/images/icon/home/mine.png',
    imageMine2: '/images/icon/home/mine-click.png'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    changeImageHome(event) {
      this.setData({
        isUp: this.data.isUp === 'up' ? true : false,
        imageStatus: this.data.isUp === 'up' ? this.data.imageHome3 : this.data.imageHome2
      })
    },
    changeHomeStatus() {
      console.log(this.data.isUp)
      if(this.data.isUp) {
        wx.pageScrollTo({
          scrollTop: 1
        })
      }
      this.setData({
        imageStatus: this.data.imageHome2,
        mineImage: this.data.imageMine1
      })
      wx.switchTab({
        url: '/pages/index/index',
      })
    },
    // addItem 新增项目
    addItem() {
      this.setData({
        isRotate: !this.data.isRotate
      })
    },
    changeRotate() {
      this.setData({
        isRotate: !this.data.isRotate
      })
    },
    // 前往我的页面
    toMinePage() {
      this.setData({
        imageStatus: this.data.imageHome1,
        mineImage: this.data.imageMine2
      })
      wx.switchTab({
        url: '/pages/mine/mine',
      })
    },
    setTabbarIcon() {
      console.log('激活内容=========')
    }
  },
  attached() {
    console.log('进入渲染页面----------')
    // this.setTabbarIcon()
    // this.setData({
    //   imageStatus: getApp().globalData.homeurl,
    //   mineImage: getApp().globalData.mineurl
    // })
    // if (getApp().globalData.tabbar !== 'mine') {
    //   getApp().globalData.homeThis = this
    //   getApp().watch(getApp().globalData.homeThis.watchBack, getApp().globalData.homeThis)
    // } else {
    //   getApp().globalData.mineThis = this
    //   getApp().watch(getApp().globalData.mineThis.watchBack, getApp().globalData.mineThis)
    // }
  },
  created() {
  }
})
